<?php
/**
 * Specifies the controller, method and params for an URL
 *
 * Application specific routes must be set in /config/routes.php
 */
namespace PUF;

class Route {
	/**
	 * String. 
	 */
	private $url;
	
	/**
	 * String
	 */
	private $controller;
	
	/**
	 * String
	 */
	private $method;
	
	/**
	 * Array? TODO
	 */
	private $params;
	
	/**
	 * Constructor
	 * 
	 * Params:
	 * $url : String.
	 * $controller : String.
	 * $method : String.
	 * $params : Array? TODO.
	 */
	public function __construct($url = null, $controller = null, $method = null, $params = null) {
		$this->url = $url;
		$this->controller = $controller;
		$this->method = $method;
		$this->params = $params;
	}
	
	/**
	 * Sets the URL
	 */
	public function setUrl($url) {
		$this->url = $url;
	}
	
	/**
	 * Sets the Controller
	 */
	public function setController($controller) {
		$this->controller = $controller;
	}
	
	/**
	 * Sets the Method
	 */
	public function setMethod($method) {
		$this->method = $method;
	}
	
	/**
	 * Sets the Params
	 */
	public function setParams($params) {
		$this->params = $params;
	}
	
	/**
	 * Gets the Params in an URLized way 
	 */
	public function getUrlParams() {
		$urlParams = '';
		
		if ($this->params) {
			arrayizeObject($this->params);
			foreach ($this->params as $key => $param) {
				if (!is_numeric($key)) {
					$urlParams .= $key . ':';
				}
				$urlParams .= $param . '/';
			}
		}
		
		return $urlParams;
	}
	
	/**
	 * Gets the URL
	 */
	public function getUrl() {
		if (!$this->url) {
			$this->url = $this->getController() . '/'
						. $this->getMethod() . '/'
						. $this->getUrlParams();
		}
		return $this->url;
	}
	
	/**
	 * Gets the Controller
	 */
	public function getController() {
		return ucfirst($this->controller);
	}
	
	/**
	 * Gets the Method
	 */
	public function getMethod() {
		return $this->method;
	}
	
	/**
	 * Gets the Params
	 */
	public function getParams() {
		return $this->params;
	}
}